﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Reflection;

using MuzičkiFeršterker.Translations;

namespace MuzičkiFeršterker
{
    [XmlRoot]
    [Serializable]
    public class Settings
    {
        #region Constructors and access
        private static volatile Settings instance;
        private static Object syncRoot = new Object();
        private Settings() { }

        public static Settings Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new Settings();
                        instance = Settings.Default;
                    }
                }
                return instance;
            }
        }
        #endregion
        #region Default values
        public static Settings Default
        {
            get 
            {
                Settings vrni = new Settings();
                    vrni.allowedFileTypes = new string[] { "*.mp3", "*.flac", "*.wav", "*.wma", "*.ogg" };
                return vrni;
            }
        }
        #endregion
        #region Saving and loading
        public static void SaveSettings() 
        {
            MuzičkiFeršterker.XmlSerializator.Save(@".\settings.xml", Settings.Instance);
        }

        public static void LoadSettings()
        {
            string pot = @".\settings.xml";
            Settings a;
            if (File.Exists(pot))
            {
                a = MuzičkiFeršterker.XmlSerializator.Load<Settings>(pot);
                if (a == null)
                    a = Default;
                else
                { 
                    /* tu dodamo še zadeve, ki se NE serializirajo, so pa v settingsih */
                    a.AllowedFileTypes = Default.AllowedFileTypes;
                }
            }
            else
                a = Default;
            instance = a;
        }
        #endregion

        #region Allowed file types
        private string[] allowedFileTypes;

        [XmlIgnore]
        public string[] AllowedFileTypes
        {
            get { return allowedFileTypes; }
            set { allowedFileTypes = Default.AllowedFileTypes; }
        }
        #endregion

        #region list of language packs
        [XmlElement("languageFiles")]
        public TransFile languageFile = new TransFile();
     
        public void AddLanguage(string path)
        {
            languageFile.setFilePath(path);
        }
        public string getLanguagePath()
        {
            return languageFile.getFilePath();
        }
        #endregion
    }
}
